package com.zl.task.controller;


import com.zl.task.dto.ShopDTO;
import com.zl.task.pojo.ServiceOrder;
import com.zl.task.service.IServiceOrderService;
import com.zl.task.util.resp.RespResult;
import com.zl.task.util.resp.RespUtil;
import com.zl.task.vo.OrderVo;
import io.swagger.annotations.ApiOperation;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yinlingeng
 * @since 2021-07-23
 */
@RestController
public class ServiceOrderController {

    @Autowired
    private IServiceOrderService orderService;

    @ApiOperation("订单展示")
    @PostMapping("/listOrders")
    public RespResult<List<OrderVo>> listOrders(Integer orderStatus, String userType, Long userId) {
        try {
            return RespUtil.success(orderService.listOrders(orderStatus,userType,userId));
        } catch (Exception e) {
            e.printStackTrace();
            return RespUtil.error(e.getMessage());
        }
    }

    @ApiOperation("订单进度更新")
    @PostMapping("/updateOrder")
    public RespResult<Boolean> updateOrder(String orderCode,String orderStatus) {
        try {
            return RespUtil.success(orderService.updateOrder(orderCode,orderStatus));
        } catch (Exception e) {
            e.printStackTrace();
            return RespUtil.error(e.getMessage());
        }
    }

    @ApiOperation("购买产品")
    @PostMapping("/shopProduct")
    public RespResult<Boolean> shopProduct(ShopDTO shopDTO) {
        try {
            return RespUtil.success(orderService.shopProduct(shopDTO));
        } catch (Exception e) {
            e.printStackTrace();
            return RespUtil.error(e.getMessage());
        }
    }

    @ApiOperation("取消购买产品")
    @PostMapping("/refundProduct")
    public RespResult<Boolean> refundProduct(String userId,String orderCode,String orderCause) {
        try {
            return RespUtil.success(orderService.refundProduct(userId,orderCode,orderCause));
        } catch (Exception e) {
            e.printStackTrace();
            return RespUtil.error(e.getMessage());
        }
    }

}

